/***************
 * Project Activity Panel
 */
AIR2.Project.Activity = function() {
    var iconClass = function(actm_type) {
        if (actm_type == 'M') // Message activity
            return 'air2-project-actm-message';
        else if (actm_type == 'J') // Journalism activity
            return 'air2-project-actm-journalism';
        else // other activity -- usually 'A'->Administrative
            return 'air2-project-actm-other';
    }
    var pactName = function(prj_act) {
        var user = AIR2.Format.userName(prj_act.User, true) + ' ';
        var link = '';
        if (prj_act.pa_ref_type == 'O') {
            link = ' ' + AIR2.Format.orgNameLong(prj_act.Organization, true);
        } else if (prj_act.pa_ref_type == 'I') {
            link = ' ' + AIR2.Format.inquiryTitle(prj_act.Inquiry, true);
        }
        return user + prj_act.ActivityMaster.actm_name + link;
    }

    return new AIR2.UI.Panel({
        colspan: 2,
        title: 'Activity',
        showTotal: true,
        iconCls: 'air2-project-activity-icon',
        storeData: AIR2.Project.ACTIVDATA,
        itemSelector: '.air2-project-activity-row',
        tpl: new Ext.XTemplate(
            '<table><tpl for=".">' +
              '<tr class="air2-project-activity-row">' +
                '<td><span class="{[this.iconClass(values.ActivityMaster.actm_type)]}">' +
                  '{[this.pactName(values)]}' +
                '</span></td>' +
                '<td><span class="air2-project-activity-date">' +
                  '{[AIR2.Format.date(values.pa_dtim)]}' +
                '</span></td>' +
              '</tr>' +
            '</tpl></table>',
            {
                compiled: true,
                disableFormats: true,
                iconClass: iconClass,
                pactName: pactName
            }
        ),
        editModal: {
            width: 650,
            items: {
                xtype: 'air2liveeditor',
                url: AIR2.Project.BASEURL + '/activity',
                sortField: 'pa_dtim',
                sortDir: 'DESC',
                pageSize: 50,
                allowEdit: false,
                allowDelete: false,
                tpl: new Ext.XTemplate(
                    '<table style="width:100%"><tpl for=".">' +
                      '<tr class="air2-project-activity-row">' +
                        '<td><span class="{[this.iconClass(values.ActivityMaster.actm_type)]}">' +
                          '{[this.pactName(values)]}' +
                        '</span></td>' +
                        '<td style="width:120px"><span class="air2-project-activity-date">' +
                          '{[AIR2.Format.dateLong(values.pa_dtim)]}' +
                        '</span></td>' +
                      '</tr>' +
                    '</tpl></table>',
                    {
                        compiled: true,
                        disableFormats: true,
                        iconClass: iconClass,
                        pactName: pactName
                    }
                )
            }
        }
    });
}
